<?php
/*
 * This is product details page.
 */
include 'config.php';
$news = true;
?>
<html>
    <head>
        <title>Admin</title>
        <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
        <style media="all" type="text/css">@import "css/all.css";</style>
    </head>
    <body>
        <div id="main">
            <?php include 'nav.php'; ?>
            <div id="middle">
                <div id="left-column">
                    <h3>News</h3>
                    <ul class="nav">
                        <li><a href="?p=me">SalusMe</a></li>                        
                        <li><a href="?p=baby">SalusBaby</a></li>
                        <li class="last" ><a href="?p=new">New Entry</a></li>
                    </ul>                    
                </div>

                <!--             Details starts-->
                <div id="center-column">

                    <?php if ($_GET['p'] == '') { ?>
                        <div class="top-bar">
                            <h1>News,</h1>
                            <div class="breadcrumbs"><a href="index">Homepage</a></div>
                        </div>
                        &nbsp;<hr>
                        <?php
                        if ($_GET['y'] == 'y') {
                            echo '<font color=green><h2>News Created.</h2></font>';
                        }
                        if ($_GET['y'] == 'u') {
                            echo '<font color=green><h2>News Updated.</h2></font>';
                        }
                        if ($_GET['y'] == 'b') {
                            echo '<font color=green><h2>News Blocked.</h2></font>';
                        }
                        if ($_GET['y'] == 'a') {
                            echo '<font color=green><h2>News Un-Blocked.</h2></font>';
                        }
                        
                        ?>

                        <b>By using this menu, you can set news details for particular product.  </b><br/>
                        <ul>
                            <li>Select product from left menu button.</li>
                            <li>It'll show you list of news.</li>
                            <li>If there is not any news, then you can insert new news.</li>
                            <li>You can modify or remove news at any time.</li>
                            <li><b>Click on "New Entry" to inserting new news. </b></li>
                        </ul>
                        <hr>
                        <?php
                    }
                    if ($_GET['p'] == 'me') {
                        $getme_news = mysql_query("select * from salus_news where pro_id  = 1 ") or die(mysql_error());
                        ?>
                        <div class="top-bar">
                            <h1>News for <b>SalusMe,</b></h1>
                            <div class="breadcrumbs"><a href="news">News</a></div>
                        </div><br/><hr>
                        <?php
                        if (mysql_num_rows($getme_news) == 0) {
                            echo '<h1>Currently, there is not news.</h1>';
                        } else {
                            ?>
                            <div class="table"  >
                                <img src="img/bg-th-left.gif" width="8" height="7" alt="" class="left" />
                                <img src="img/bg-th-right.gif" width="7" height="7" alt="" class="right" />
                                <table class="listing" cellpadding="0" cellspacing="0" width="100%;" >
                                    <tr>
                                        <th class="first" width="20%">Title</th>
                                        <th width="70%" >Content</th>
                                        <th class="last" width="10%">Action</th>
                                    </tr>

                                    <?php while ($row = mysql_fetch_array($getme_news)) { ?>
                                        <tr class="bg" >
                                            <td><b><?= $row['title'] ?></b></td>
                                            <td><?= $row['content'] ?></td>
                                            <td><a href="?p=edit&id=<?= $row['sr'] ?>"><img src="img/edit-icon.gif" title="Edit News Info" /></a>
                                                <?php
                                                if ($row['banned'] == 0) {
                                                    echo '<a href=?p=b&sr=' . $row['sr'] . '><img src="img/banned.jpg" title="Block This User" /></a>';
                                                } else {
                                                    echo '<a href=?p=a&sr=' . $row['sr'] . '><img src="img/approve.jpg" title="UnBlock This User" /></a>';
                                                }
                                                ?>
                                            </td>
                                        </tr>
                                    <?php }
                                    ?>


                                </table>
                            </div>
                            <?php
                        }
                    }
                    if ($_GET['p'] == 'baby') {
                        $getbaby_news = mysql_query("select * from salus_news where pro_id  = 2 ") or die(mysql_error());
                        ?>
                        <div class="top-bar">
                            <h1>News for <b>SalusBaby,</b></h1>
                            <div class="breadcrumbs"><a href="news">News</a></div>
                        </div><br/><hr>
                        <?php
                        if (mysql_num_rows($getbaby_news) == 0) {
                            echo '<h1>Currently, there is not news.</h1>';
                        } else {
                            ?>
                            <div class="table"  >
                                <img src="img/bg-th-left.gif" width="8" height="7" alt="" class="left" />
                                <img src="img/bg-th-right.gif" width="7" height="7" alt="" class="right" />
                                <table class="listing" cellpadding="0" cellspacing="0" width="100%;" >
                                    <tr>
                                        <th class="first" width="20%">Title</th>
                                        <th width="70%" >Content</th>
                                        <th class="last" width="10%">Action</th>
                                    </tr>

                                    <?php while ($row = mysql_fetch_array($getbaby_news)) { ?>
                                        <tr class="bg" >
                                            <td><b><?= $row['title'] ?></b></td>
                                            <td><?= $row['content'] ?></td>
                                            <td><a href="?p=edit&id=<?= $row['sr'] ?>"><img src="img/edit-icon.gif" title="Edit News Info" /></a>
                                                <?php
                                                if ($row['banned'] == 0) {
                                                    echo '<a href=?p=b&sr=' . $row['sr'] . '><img src="img/banned.jpg" title="Block This User" /></a>';
                                                } else {
                                                    echo '<a href=?p=a&sr=' . $row['sr'] . '><img src="img/approve.jpg" title="UnBlock This User" /></a>';
                                                }
                                                ?>
                                            </td>
                                        </tr>
                                    <?php }
                                    ?>


                                </table>
                            </div>

                            <?php
                        }
                    }
                    if ($_GET['p'] == 'new') {
                        ?>
                        <div class="top-bar">
                            <h1>Create New News Entry,</h1>
                            <div class="breadcrumbs"><a href="news">News</a></div>
                        </div><br/><br><br><hr>
                        <form method="post" action="Com/news_operations.php">
                            <table>
                                <tr>
                                    <td>Title :</td>
                                    <td> <input type="text" name="title" placeholder="News Title" required style="width: 300px;" /> </td>
                                </tr>
                                <tr>
                                    <td>Details :</td>
                                    <td>
                                        <textarea name="content"  rows="5" placeholder="Details of news" required style="width: 300px;" ></textarea>
                                    </td>
                                </tr>
                                <tr>
                                    <td>Choose Product :</td>
                                    <td>
                                        <select name="pro_id" required style="width: 100px;">
                                            <option value="1" >Salus ME</option>
                                            <option value="2" >Salus Baby</option>
                                        </select>
                                    </td>
                                </tr>
                                <tr>
                                    <td><input type="hidden" name="action" value="new" /></td>
                                    <td><input type="submit" value="Create News" /> </td>
                                </tr>
                            </table>
                        </form>
                        <?php
                    }
                    if ($_GET['p'] == 'edit') {
                        $sr = $_GET['id'];
                        ?>
                        <div class="top-bar">
                            <h1>Update News Entry,</h1>
                            <div class="breadcrumbs"><a href="news">News</a></div>
                        </div><br/><br><br><hr> 
                        <?php
                        $get_news = mysql_query("select * from salus_news where sr = '".$sr."' ") or die(mysql_error());
                        while ($row1 = mysql_fetch_array($get_news)) {
                            ?>
                            <form method="post" action="Com/news_operations.php">
                                <table>
                                    <tr>
                                        <td>Title :</td>
                                        <td> <input type="text" name="title" placeholder="News Title" required style="width: 300px;" value="<?=$row1['title']?>" /> </td>
                                    </tr>
                                    <tr>
                                        <td>Details :</td>
                                        <td>
                                            <textarea name="content"  rows="5" placeholder="Details of news" required style="width: 300px;" ><?=$row1['content']?></textarea>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Choose Product :</td>
                                        <td>
                                            <select name="pro_id" required style="width: 100px;">
                                                <option value="1" <?php if($row1['pro_id']==1){?> selected="selected"  <?php } ?> >Salus ME</option>
                                                <option value="2" <?php if($row1['pro_id']==2){?> selected="selected"  <?php } ?>>Salus Baby</option>
                                            </select>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <input type="hidden" name="sr" value="<?=$sr?>" />
                                            <input type="hidden" name="action" value="update" />
                                        </td>
                                        <td><input type="submit" value="Update News" /> </td>
                                    </tr>
                                </table>
                            </form> 


                            <?php
                        } 
                    }# edit over
                    
                    if($_GET['p']=='b'){
                        $sr = $_GET['sr'];
                        mysql_query("update salus_news set banned= 1 where sr= '$sr' ") or die(mysql_error());
                        header('Location:news?y=b');
                    }
                    if($_GET['p']=='a'){
                        $sr = $_GET['sr'];
                        mysql_query("update salus_news set banned= 0 where sr= '$sr' ") or die(mysql_error());
                        header('Location:news?y=a');
                    }
                    
                    ?>    

                </div>
                <div id="right-column">
                    <strong class="h">INFO</strong>
                    <div class="box">You can manage news for all products.</div>
                    <div id="google_translate_element"></div>
                </div>
            </div>
            <div id="footer"></div>
        </div>


    </body>
</html>
